package cn.hiapi.core.basic.abs;

import cn.hiapi.core.basic.Nuwa;
import cn.hiapi.core.basic.response.DefaultResponseCode;
import cn.hiapi.core.basic.response.ResponseEntity;

/**
 * @author AdinZ
 * @date 2024/1/12 10:57
 */
public abstract class AbsResponse extends Nuwa {

    public <T> ResponseEntity<T> toResult(int code, String message, T data) {
        ResponseEntity<T> response = new ResponseEntity<>();
        response.setCode(code);
        response.setMessage(message);
        response.setData(data);
        return response;
    }

    public <T> ResponseEntity<T> toError(int code, String message) {
        return toResult(code, message, null);
    }

    public <T> ResponseEntity<T> toError(String message) {
        return toError(300, message);
    }

    public <T> ResponseEntity<T> toError() {
        return toError("参数错误");
    }

    public <T> ResponseEntity<T> toSuccess(String message, T data) {
        return toResult(DefaultResponseCode.SUCCESS.getCode(),message,data);
    }

    public <T> ResponseEntity<T> toSuccess(T data) {
        return toSuccess(DefaultResponseCode.SUCCESS.getRemark(), data);
    }

    public <T> ResponseEntity<T> toSuccess() {
        return toSuccess(null);
    }

}
